<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>联系我们</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        }

        body {
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
            padding: 20px;
        }

        .container {
            background: white;
            border-radius: 12px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
            width: 100%;
            max-width: 500px;
            overflow: hidden;
        }

        .header {
            background: #4a6fa5;
            color: white;
            padding: 25px;
            text-align: center;
        }

        .header h1 {
            font-size: 28px;
            margin-bottom: 10px;
        }

        .header p {
            font-size: 16px;
            opacity: 0.9;
        }

        .form-container {
            padding: 30px;
        }

        .form-group {
            margin-bottom: 20px;
        }

        label {
            display: block;
            margin-bottom: 8px;
            font-weight: 600;
            color: #333;
        }

        input, textarea {
            width: 100%;
            padding: 14px;
            border: 1px solid #ddd;
            border-radius: 6px;
            font-size: 16px;
            transition: border 0.3s;
        }

        input:focus, textarea:focus {
            outline: none;
            border-color: #4a6fa5;
            box-shadow: 0 0 0 2px rgba(74, 111, 165, 0.2);
        }

        textarea {
            min-height: 120px;
            resize: vertical;
        }

        button {
            background: #4a6fa5;
            color: white;
            border: none;
            padding: 15px;
            width: 100%;
            border-radius: 6px;
            font-size: 18px;
            font-weight: 600;
            cursor: pointer;
            transition: background 0.3s;
            margin-bottom: 15px;
        }

        button:hover {
            background: #3a5a80;
        }

        .success-message {
            background: #d4edda;
            color: #155724;
            padding: 15px;
            border-radius: 6px;
            margin-top: 20px;
            display: none;
        }

        .error-message {
            background: #f8d7da;
            color: #721c24;
            padding: 15px;
            border-radius: 6px;
            margin-top: 20px;
            display: none;
        }

        .instructions {
            background: #f8f9fa;
            padding: 20px;
            margin-top: 30px;
            border-radius: 8px;
            border-left: 4px solid #4a6fa5;
        }

        .instructions h3 {
            margin-bottom: 10px;
            color: #333;
        }

        .instructions ol {
            padding-left: 20px;
        }

        .instructions li {
            margin-bottom: 8px;
            color: #555;
        }

        .contact-info {
            background: #e3f2fd;
            padding: 20px;
            margin-top: 20px;
            border-radius: 8px;
            border-left: 4px solid #2196F3;
        }

        .contact-info h3 {
            margin-bottom: 10px;
            color: #333;
        }

        .contact-info p {
            margin-bottom: 8px;
            color: #555;
        }

        .email-link {
            display: inline-block;
            background: #4a6fa5;
            color: white;
            text-decoration: none;
            padding: 12px 20px;
            border-radius: 6px;
            font-weight: 600;
            margin-top: 15px;
            transition: background 0.3s;
            border: none;
            cursor: pointer;
        }

        .email-link:hover {
            background: #3a5a80;
        }

        .tab-container {
            margin-bottom: 20px;
        }

        .tab-button {
            background-color: #f1f1f1;
            border: none;
            outline: none;
            cursor: pointer;
            padding: 10px 16px;
            transition: 0.3s;
            font-size: 16px;
            border-radius: 6px 6px 0 0;
        }

        .tab-button.active {
            background-color: #4a6fa5;
            color: white;
        }

        .tab-content {
            display: none;
            padding: 6px 12px;
        }

        .tab-content.active {
            display: block;
        }

        @media (max-width: 600px) {
            .container {
                border-radius: 0;
            }

            .header {
                padding: 20px;
            }

            .form-container {
                padding: 20px;
            }
        }
    </style>
</head>
<body>
<div class="container">
    <div class="header">
        <h1>联系我们</h1>
        <p>通过以下方式联系我们</p>
    </div>

    <div class="form-container">
        <div class="tab-container">
            <button class="tab-button active" onclick="openTab(event, 'online-form')">在线表单</button>
            <button class="tab-button" onclick="openTab(event, 'email-client')">邮件客户端</button>
        </div>

        <div id="online-form" class="tab-content active">
            <form id="contact-form">
                <div class="form-group">
                    <label for="name">您的姓名</label>
                    <input type="text" id="name" name="name" required placeholder="请输入您的姓名">
                </div>

                <div class="form-group">
                    <label for="subject">主题</label>
                    <input type="text" id="subject" name="subject" required placeholder="请输入邮件主题">
                </div>

                <div class="form-group">
                    <label for="message">留言内容及您的联系方式</label>
                    <textarea id="message" name="message" required placeholder="请详细描述您的问题或需求"></textarea>
                </div>

                <button type="submit">发送邮件</button>
            </form>

            <div id="success-message" class="success-message">
                邮件发送成功！我们会尽快回复您。
            </div>

            <div id="error-message" class="error-message">
                邮件发送失败，请稍后重试或使用其他联系方式。
            </div>
        </div>

        <div id="email-client" class="tab-content">
            <div class="instructions">
                <h3>使用邮件客户端：</h3>
                <p>您可以通过以下方式使用邮件客户端联系我们：</p>
                <p><strong>邮箱：</strong>421731394@qq.com</p>
                <p>点击下面的按钮可以直接使用您的邮件客户端发送邮件：</p>
                
                <a href="mailto:421731394@qq.com" class="email-link">发送邮件</a>
            </div>
        </div>

        <div class="contact-info">
            <h3>使用说明：</h3>
            <ol>
                <li><strong>在线表单</strong>：填写表单后点击发送，我们将通过EmailJS服务接收您的消息</li>
                <li><strong>邮件客户端</strong>：点击"发送邮件"按钮将打开您默认的邮件客户端</li>
                <li>如果您无法通过在线表单发送邮件，请使用邮件客户端方式</li>
                <li>我们会在收到消息后尽快回复您</li>
                <li><strong>BUG反馈</strong>：如果您发现软件BUG，可以<a href="https://www.bilibili.com/video/BV1sxndzvEwa/?share_source=copy_web&vd_source=3b3e1ae9fa3fe12b20e8ba6eb1640b56" target="_blank" style="color: #4a6fa5; text-decoration: underline;">点击这里评论反馈BUG</a></li>
            </ol>
        </div>
    </div>
</div>

<!-- 引入EmailJS SDK -->
<script src="https://cdn.jsdelivr.net/npm/emailjs-com@3.2.0/dist/email.min.js"></script>
<script>
    // 初始化EmailJS（需要替换为你的User ID）
    (function(){
        emailjs.init("2B0Bb5qN0_bP8tt7O"); // 替换为你的EmailJS公钥
    })();

    // 表单提交处理
    document.getElementById('contact-form').addEventListener('submit', function(event) {
        event.preventDefault();

        // 显示加载状态
        const submitButton = event.target.querySelector('button[type="submit"]');
        const originalText = submitButton.textContent;
        submitButton.textContent = '发送中...';
        submitButton.disabled = true;

        // 获取表单数据
        const formData = {
            from_name: document.getElementById('name').value,
            from_email: document.getElementById('email').value,
            subject: document.getElementById('subject').value,
            message: document.getElementById('message').value
        };

        // 验证表单数据
        if (!formData.from_name || !formData.from_email || !formData.subject || !formData.message) {
            alert('请填写所有必填字段');
            submitButton.textContent = originalText;
            submitButton.disabled = false;
            return;
        }

        // 使用EmailJS发送邮件（需要替换为你的Service ID和Template ID）
        emailjs.send("service_9shdavx", "template_pgg2h8q", formData)
            .then(function(response) {
                console.log('邮件发送成功!', response.status, response.text);
                document.getElementById('success-message').style.display = 'block';
                document.getElementById('error-message').style.display = 'none';
                document.getElementById('contact-form').reset();
            }, function(error) {
                console.log('邮件发送失败...', error);
                // 显示更详细的错误信息
                document.getElementById('error-message').innerHTML = '邮件发送失败，请稍后重试或使用其他联系方式。错误详情：' + (error.text || error.message || '未知错误');
                document.getElementById('error-message').style.display = 'block';
                document.getElementById('success-message').style.display = 'none';
            })
            .finally(function() {
                // 恢复按钮状态
                submitButton.textContent = originalText;
                submitButton.disabled = false;
            });
    });

    // Tab切换功能
    function openTab(evt, tabName) {
        // 隐藏所有tab内容
        var tabcontent = document.getElementsByClassName("tab-content");
        for (var i = 0; i < tabcontent.length; i++) {
            tabcontent[i].className = tabcontent[i].className.replace(" active", "");
        }

        // 移除所有tab按钮的active类
        var tabbuttons = document.getElementsByClassName("tab-button");
        for (var i = 0; i < tabbuttons.length; i++) {
            tabbuttons[i].className = tabbuttons[i].className.replace(" active", "");
        }

        // 显示当前tab，给按钮添加active类
        document.getElementById(tabName).className += " active";
        evt.currentTarget.className += " active";
    }

    // 检测是否可以使用邮件客户端
    document.addEventListener('DOMContentLoaded', function() {
        const emailLinks = document.querySelectorAll('a[href^="mailto:"]');
        
        emailLinks.forEach(function(link) {
            link.addEventListener('click', function(e) {
                // 显示提示信息
                setTimeout(function() {
                    alert('如果您的系统已配置邮件客户端，将自动打开。如果没有配置，请手动发送邮件至：421731394@qq.com');
                }, 100);
            });
        });
    });
</script>
</body>
</html>